<template>
  <div class="school-home">
    <!-- banner -->
    <home-banner :bannerList="schoolHomeBannerList"></home-banner>
    <div class="container">
      <home-course :courseList="schoolHomeCourseList"></home-course>
      <home-teacher :teacherList="schoolHomeTeacherList"></home-teacher>
      <home-news :newsList="schoolHomeNewsList"></home-news>
    </div>
  </div>
</template>

<script>
import HomeBanner from './components/homeBanner'
import HomeCourse from './components/homeCourse'
import HomeTeacher from './components/homeTeacher'
import HomeNews from './components/homeNews'
export default {
  components: {
    HomeBanner,
    HomeCourse,
    HomeTeacher,
    HomeNews
  },
  inject: ['reload'],
  data() {
    return {
      schoolHomeBannerList: [],
      schoolHomeInfo: {},
      schoolHomeCourseList: [],
      schoolHomeTeacherList: [],
      schoolHomeNewsList: []
    }
  },
  beforeRouteEnter(to, from, next) {
    next(vm => {
      // 路由拦截，默认机构id为1时，跳转到平台首页
      if (to.params.id == 1) {
        vm.$router.push({
          path: '/'
        })
      }
    })
  },
  mounted() {
    this.handleSchoolHomeInit()
    this.handleSchoolBanner()
  },
  methods: {
    // 初始化主页数据
    handleSchoolHomeInit() {
      this.$api.getSchoolHome(this.$route.params.id, res => {
        let data = res.data
        this.schoolHomeInfo = data.info
        this.schoolHomeCourseList = data.course
        this.schoolHomeTeacherList = data.teacher
        this.schoolHomeNewsList = data.topic
      })
    },
    // 获取机构banner
    handleSchoolBanner() {
      this.$api.getConfigBanner(
        {
          type: 'school',
          mhm_id: this.$route.params.id
        },
        res => {
          this.schoolHomeBannerList = res.data
        }
      )
    }
  }
}
</script>
<style lang="scss" scoped>
.school-home {
  .home-column {
    margin-top: 60px;
    background-color: #fff;
  }
}
</style>
